package aigle.bvieillard.gmf.tp2.diagram.part;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.tooling.runtime.update.DiagramUpdater;

import aigle.bvieillard.gmf.tp2.Compose;
import aigle.bvieillard.gmf.tp2.Ingredient;
import aigle.bvieillard.gmf.tp2.LivreRecettes;
import aigle.bvieillard.gmf.tp2.Localisation;
import aigle.bvieillard.gmf.tp2.Recette;
import aigle.bvieillard.gmf.tp2.Vin;
import aigle.bvieillard.gmf.tp2.diagram.edit.parts.ComposeEditPart;
import aigle.bvieillard.gmf.tp2.diagram.edit.parts.IngredientEditPart;
import aigle.bvieillard.gmf.tp2.diagram.edit.parts.LivreRecettesEditPart;
import aigle.bvieillard.gmf.tp2.diagram.edit.parts.LocalisationEditPart;
import aigle.bvieillard.gmf.tp2.diagram.edit.parts.RecetteEditPart;
import aigle.bvieillard.gmf.tp2.diagram.edit.parts.RecetteOrigineRegionaleEditPart;
import aigle.bvieillard.gmf.tp2.diagram.edit.parts.VinEditPart;
import aigle.bvieillard.gmf.tp2.diagram.providers.Tp2ElementTypes;

/**
 * @generated
 */
public class Tp2DiagramUpdater {

	/**
	 * @generated
	 */
	public static List<Tp2NodeDescriptor> getSemanticChildren(View view) {
		switch (Tp2VisualIDRegistry.getVisualID(view)) {
		case LivreRecettesEditPart.VISUAL_ID:
			return getLivreRecettes_1000SemanticChildren(view);
		}
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2NodeDescriptor> getLivreRecettes_1000SemanticChildren(
			View view) {
		if (!view.isSetElement()) {
			return Collections.emptyList();
		}
		LivreRecettes modelElement = (LivreRecettes) view.getElement();
		LinkedList<Tp2NodeDescriptor> result = new LinkedList<Tp2NodeDescriptor>();
		for (Iterator<?> it = modelElement.getDepartements().iterator(); it
				.hasNext();) {
			Localisation childElement = (Localisation) it.next();
			int visualID = Tp2VisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == LocalisationEditPart.VISUAL_ID) {
				result.add(new Tp2NodeDescriptor(childElement, visualID));
				continue;
			}
		}
		for (Iterator<?> it = modelElement.getRecettes().iterator(); it
				.hasNext();) {
			Recette childElement = (Recette) it.next();
			int visualID = Tp2VisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == RecetteEditPart.VISUAL_ID) {
				result.add(new Tp2NodeDescriptor(childElement, visualID));
				continue;
			}
		}
		for (Iterator<?> it = modelElement.getIngredients().iterator(); it
				.hasNext();) {
			Ingredient childElement = (Ingredient) it.next();
			int visualID = Tp2VisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == IngredientEditPart.VISUAL_ID) {
				result.add(new Tp2NodeDescriptor(childElement, visualID));
				continue;
			}
		}
		for (Iterator<?> it = modelElement.getVins().iterator(); it.hasNext();) {
			Vin childElement = (Vin) it.next();
			int visualID = Tp2VisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == VinEditPart.VISUAL_ID) {
				result.add(new Tp2NodeDescriptor(childElement, visualID));
				continue;
			}
		}
		return result;
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getContainedLinks(View view) {
		switch (Tp2VisualIDRegistry.getVisualID(view)) {
		case LivreRecettesEditPart.VISUAL_ID:
			return getLivreRecettes_1000ContainedLinks(view);
		case LocalisationEditPart.VISUAL_ID:
			return getLocalisation_2001ContainedLinks(view);
		case RecetteEditPart.VISUAL_ID:
			return getRecette_2002ContainedLinks(view);
		case IngredientEditPart.VISUAL_ID:
			return getIngredient_2003ContainedLinks(view);
		case VinEditPart.VISUAL_ID:
			return getVin_2004ContainedLinks(view);
		case ComposeEditPart.VISUAL_ID:
			return getCompose_4001ContainedLinks(view);
		}
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getIncomingLinks(View view) {
		switch (Tp2VisualIDRegistry.getVisualID(view)) {
		case LocalisationEditPart.VISUAL_ID:
			return getLocalisation_2001IncomingLinks(view);
		case RecetteEditPart.VISUAL_ID:
			return getRecette_2002IncomingLinks(view);
		case IngredientEditPart.VISUAL_ID:
			return getIngredient_2003IncomingLinks(view);
		case VinEditPart.VISUAL_ID:
			return getVin_2004IncomingLinks(view);
		case ComposeEditPart.VISUAL_ID:
			return getCompose_4001IncomingLinks(view);
		}
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getOutgoingLinks(View view) {
		switch (Tp2VisualIDRegistry.getVisualID(view)) {
		case LocalisationEditPart.VISUAL_ID:
			return getLocalisation_2001OutgoingLinks(view);
		case RecetteEditPart.VISUAL_ID:
			return getRecette_2002OutgoingLinks(view);
		case IngredientEditPart.VISUAL_ID:
			return getIngredient_2003OutgoingLinks(view);
		case VinEditPart.VISUAL_ID:
			return getVin_2004OutgoingLinks(view);
		case ComposeEditPart.VISUAL_ID:
			return getCompose_4001OutgoingLinks(view);
		}
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getLivreRecettes_1000ContainedLinks(
			View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getLocalisation_2001ContainedLinks(
			View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getRecette_2002ContainedLinks(
			View view) {
		Recette modelElement = (Recette) view.getElement();
		LinkedList<Tp2LinkDescriptor> result = new LinkedList<Tp2LinkDescriptor>();
		result.addAll(getContainedTypeModelFacetLinks_Compose_4001(modelElement));
		result.addAll(getOutgoingFeatureModelFacetLinks_Recette_OrigineRegionale_4002(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getIngredient_2003ContainedLinks(
			View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getVin_2004ContainedLinks(View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getCompose_4001ContainedLinks(
			View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getLocalisation_2001IncomingLinks(
			View view) {
		Localisation modelElement = (Localisation) view.getElement();
		Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences = EcoreUtil.CrossReferencer
				.find(view.eResource().getResourceSet().getResources());
		LinkedList<Tp2LinkDescriptor> result = new LinkedList<Tp2LinkDescriptor>();
		result.addAll(getIncomingFeatureModelFacetLinks_Recette_OrigineRegionale_4002(
				modelElement, crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getRecette_2002IncomingLinks(View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getIngredient_2003IncomingLinks(
			View view) {
		Ingredient modelElement = (Ingredient) view.getElement();
		Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences = EcoreUtil.CrossReferencer
				.find(view.eResource().getResourceSet().getResources());
		LinkedList<Tp2LinkDescriptor> result = new LinkedList<Tp2LinkDescriptor>();
		result.addAll(getIncomingTypeModelFacetLinks_Compose_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getVin_2004IncomingLinks(View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getCompose_4001IncomingLinks(View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getLocalisation_2001OutgoingLinks(
			View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getRecette_2002OutgoingLinks(View view) {
		Recette modelElement = (Recette) view.getElement();
		LinkedList<Tp2LinkDescriptor> result = new LinkedList<Tp2LinkDescriptor>();
		result.addAll(getContainedTypeModelFacetLinks_Compose_4001(modelElement));
		result.addAll(getOutgoingFeatureModelFacetLinks_Recette_OrigineRegionale_4002(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getIngredient_2003OutgoingLinks(
			View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getVin_2004OutgoingLinks(View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<Tp2LinkDescriptor> getCompose_4001OutgoingLinks(View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	private static Collection<Tp2LinkDescriptor> getContainedTypeModelFacetLinks_Compose_4001(
			Recette container) {
		LinkedList<Tp2LinkDescriptor> result = new LinkedList<Tp2LinkDescriptor>();
		for (Iterator<?> links = container.getComposes().iterator(); links
				.hasNext();) {
			EObject linkObject = (EObject) links.next();
			if (false == linkObject instanceof Compose) {
				continue;
			}
			Compose link = (Compose) linkObject;
			if (ComposeEditPart.VISUAL_ID != Tp2VisualIDRegistry
					.getLinkWithClassVisualID(link)) {
				continue;
			}
			Ingredient dst = link.get_ingredient();
			result.add(new Tp2LinkDescriptor(container, dst, link,
					Tp2ElementTypes.Compose_4001, ComposeEditPart.VISUAL_ID));
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection<Tp2LinkDescriptor> getIncomingTypeModelFacetLinks_Compose_4001(
			Ingredient target,
			Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences) {
		LinkedList<Tp2LinkDescriptor> result = new LinkedList<Tp2LinkDescriptor>();
		Collection<EStructuralFeature.Setting> settings = crossReferences
				.get(target);
		for (EStructuralFeature.Setting setting : settings) {
			if (setting.getEStructuralFeature() != aigle.bvieillard.gmf.tp2.tp2Package.eINSTANCE
					.getCompose__ingredient()
					|| false == setting.getEObject() instanceof Compose) {
				continue;
			}
			Compose link = (Compose) setting.getEObject();
			if (ComposeEditPart.VISUAL_ID != Tp2VisualIDRegistry
					.getLinkWithClassVisualID(link)) {
				continue;
			}
			if (false == link.eContainer() instanceof Recette) {
				continue;
			}
			Recette container = (Recette) link.eContainer();
			result.add(new Tp2LinkDescriptor(container, target, link,
					Tp2ElementTypes.Compose_4001, ComposeEditPart.VISUAL_ID));

		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection<Tp2LinkDescriptor> getIncomingFeatureModelFacetLinks_Recette_OrigineRegionale_4002(
			Localisation target,
			Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences) {
		LinkedList<Tp2LinkDescriptor> result = new LinkedList<Tp2LinkDescriptor>();
		Collection<EStructuralFeature.Setting> settings = crossReferences
				.get(target);
		for (EStructuralFeature.Setting setting : settings) {
			if (setting.getEStructuralFeature() == aigle.bvieillard.gmf.tp2.tp2Package.eINSTANCE
					.getRecette_OrigineRegionale()) {
				result.add(new Tp2LinkDescriptor(setting.getEObject(), target,
						Tp2ElementTypes.RecetteOrigineRegionale_4002,
						RecetteOrigineRegionaleEditPart.VISUAL_ID));
			}
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection<Tp2LinkDescriptor> getOutgoingFeatureModelFacetLinks_Recette_OrigineRegionale_4002(
			Recette source) {
		LinkedList<Tp2LinkDescriptor> result = new LinkedList<Tp2LinkDescriptor>();
		Localisation destination = source.getOrigineRegionale();
		if (destination == null) {
			return result;
		}
		result.add(new Tp2LinkDescriptor(source, destination,
				Tp2ElementTypes.RecetteOrigineRegionale_4002,
				RecetteOrigineRegionaleEditPart.VISUAL_ID));
		return result;
	}

	/**
	 * @generated
	 */
	public static final DiagramUpdater TYPED_INSTANCE = new DiagramUpdater() {
		/**
		 * @generated
		 */
		@Override
		public List<Tp2NodeDescriptor> getSemanticChildren(View view) {
			return Tp2DiagramUpdater.getSemanticChildren(view);
		}

		/**
		 * @generated
		 */
		@Override
		public List<Tp2LinkDescriptor> getContainedLinks(View view) {
			return Tp2DiagramUpdater.getContainedLinks(view);
		}

		/**
		 * @generated
		 */
		@Override
		public List<Tp2LinkDescriptor> getIncomingLinks(View view) {
			return Tp2DiagramUpdater.getIncomingLinks(view);
		}

		/**
		 * @generated
		 */
		@Override
		public List<Tp2LinkDescriptor> getOutgoingLinks(View view) {
			return Tp2DiagramUpdater.getOutgoingLinks(view);
		}
	};

}
